<!DOCTYPE html>
<html lang="zh-CN">
<head>

<#include "bases/global_style.ftl"> 
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
</head>

<body>
 
	<div class="page-container" id="loading">

				<div class="row-fluid">
					<div class="span12">
						<div class="portlet box green">
							<div class="portlet-title">
								<div class="caption">
										<i class="fa fa-cogs"></i><#if id??>修改套餐资费<#else>新增常规资费</#if>
								</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
							</div>

							<div class="portlet-body flip-scroll">
								<form class="form-horizontal" role="form" id="dataform">
								
							    	<input type="hidden" name="id" value="<#if id??>${id}</#if>">
									<div class="form-group">
										<label class="col-sm-4 control-label">资费类型</label>
										<div class="col-sm-5">
	                                        <label class="radio-inline">
											  <input type="radio" name="type" class="role1Btn" id="" value="1"   <#if conventionalPostageModel.type??><#if conventionalPostageModel.type==1>checked</#if></#if>   required> 按里程收费
											</label>
											<label class="radio-inline">
											  <input type="radio" name="type" class="role2Btn" id="" value="2"   <#if conventionalPostageModel.type??><#if conventionalPostageModel.type==2>checked</#if></#if> required> 按次数收费
											</label>
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-4 control-label">资费名称<span
											class="fill-must">*</span> </label>
										<div class="col-sm-5">
											  <input type="text" class="form-control" name="name" placeholder=""  value="<#if conventionalPostageModel.name??>${conventionalPostageModel.name}</#if>" required>
										</div>
									</div>

									<!-- 按里程收费-->
									<div class="role1">
										<div class="form-group">
											<label class="col-sm-4 control-label">单价<span
												class="fill-must">*</span> </label>
											<div class="col-sm-5">
												    <input type="number" name="unitprice1" class="form-control" placeholder=""  onchange="$(this).next().val($(this).val()*100)"  value="<#if conventionalPostageModel.unitprice??>${conventionalPostageModel.unitprice/100}</#if>" required>
											        <input type="hidden"  name="unitprice" value="<#if conventionalPostageModel.unitprice??>${conventionalPostageModel.unitprice}</#if>">
											</div>
											<div class="col-sm-2 sheet-inputContent"
												style="padding-left: 0;">元 / 公里</div>
										</div>
									</div>

									<!-- 按次数收费 -->
									<div class="role2" style="display: none;">
										<div class="form-group">
											<label class="col-sm-4 control-label">单价<span
												class="fill-must">*</span> </label>
											<div class="col-sm-5">
												 <input type="number" name="unitprice2" class="form-control" placeholder="" onchange="$(this).next().val($(this).val()*100)"   value="<#if conventionalPostageModel.unitprice??>${conventionalPostageModel.unitprice/100}</#if>" required>
											        <input type="hidden"  name="unitprice" value="<#if conventionalPostageModel.unitprice??>${conventionalPostageModel.unitprice}</#if>">
											</div>
											<div class="col-sm-2 sheet-inputContent"
												style="padding-left: 0;">元 / 次</div>
										</div>
									</div>

								    <div class="form-group">
								     <label class="col-sm-4 control-label">地区<span class="fill-must">*</span></label>
								     <div class="col-sm-8">
								        <label class="radio-inline">
										  <input type="radio" name="areaRadio" id="" value="1"  <#if conventionalPostageModel.areaRadio??><#if conventionalPostageModel.areaRadio==1>checked</#if></#if> required> 全地区
										</label>
										
								      </div>
									    
								      <div class="col-sm-offset-4 col-sm-8">
										  <label class="radio-inline">
											  <input type="radio" name="areaRadio" id="" value="2"   <#if conventionalPostageModel.areaRadio??><#if conventionalPostageModel.areaRadio==2>checked</#if></#if> required> 选择地区
										  </label>
										  
										  <div style="margin-top: 20px"></div>
										  <label class="radio-inline">省份
											  <select id="provinceids" multiple="multiple" name="provinceids">
											  </select>
										  </label>
								
										   <div style="margin-top: 20px"></div>
										   <label class="radio-inline">地市
											  <select id="cityids" multiple="multiple"  name="cityids">
											 </select>
										  </label>
								        </div>
								    </div>

								  <div class="form-group">
								    <label class="col-sm-4 control-label">生效周期<span class="fill-must">*</span></label>
								    <div class="col-sm-8">
								    	<div class="sheet-inputContent">生效日期</div>
								        <label class="radio-inline">
										  <input type="radio" name="beginTimeRadio" id="" value="1" <#if conventionalPostageModel.beginTimeRadio??><#if conventionalPostageModel.beginTimeRadio==1>checked</#if></#if> required> 即时生效
										</label>
										<label class="radio-inline">
										  <input type="radio" name="beginTimeRadio" id="" value="2" style="margin-top: 10px;" <#if conventionalPostageModel.beginTimeRadio??><#if conventionalPostageModel.beginTimeRadio==2>checked</#if></#if> required> 
										  <input type="text"  name="beginTime" id="beginTime" class="form-control" placeholder="请选择生效时间" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="<#if conventionalPostageModel.beginTime??>${conventionalPostageModel.beginTime}</#if>">
										</label>
								    </div>
								    
								     <div class="col-sm-offset-4 col-sm-8">
								    	<div class="sheet-inputContent">截止日期</div>
								        <label class="radio-inline">
										  <input type="radio" name="endTimeRadio" id="" value="1" <#if conventionalPostageModel.endTimeRadio??><#if conventionalPostageModel.endTimeRadio==1>checked</#if></#if> required> 不限日期
										</label>
										<label class="radio-inline">
										  <input type="radio" name="endTimeRadio" id="" value="2" style="margin-top: 10px;" <#if conventionalPostageModel.endTimeRadio??><#if conventionalPostageModel.endTimeRadio==2>checked</#if></#if> required> 
										  <input type="text" name="endTime" id="endTime" class="form-control" placeholder="请选择截止日期" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="<#if conventionalPostageModel.endTime??>${conventionalPostageModel.endTime}</#if>">
										</label>
								    </div>
								  </div> 

									<div class="form-group">
										<div class="col-sm-offset-4 col-sm-5 sheet-btnBar">
											<button type="button" class="btn btn-info sheet-btn" onclick="submitFormdata()">保存</button>
											<button type="button" class="btn btn-default sheet-btn" onclick="closeDialog()">取消</button>
										</div>
									</div>

									<div class="form-group"  style="display: none">
										<div class="col-sm-offset-4 col-sm-5 error-resgister">
											<span id="errorContent">错误提示错误提示错误提示</span>
											<!-- 错误提示 -->
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			
<script>  
	$(document).ready(function() {
		
	    var type="<#if conventionalPostageModel.type??>${conventionalPostageModel.type}</#if>";
	    if(type=="1"||type==""){
	    	$(".role1").css("display","block");
	    	$(".role2").css("display","none");
	    	$(".role2").find("input").attr("disabled",true);   
	    }else if(type=="2"){
	       	$(".role1").css("display","none");
	     	$(".role2").css("display","block");
			$(".role1").find("input").attr("disabled",true);   
	    }
	    
	    
	    dataform=$("#dataform").validate();
	 	selectEvent();//下拉框多选
	 	
	    $('#provinceids').val('<#if conventionalPostageModel.provinceids??>${conventionalPostageModel.provinceids}</#if>'.split(","));
        $('#provinceids').multiselect("refresh");  
	    $('#cityids').val('<#if conventionalPostageModel.cityids??>${conventionalPostageModel.cityids}</#if>'.split(","));
        $('#cityids').multiselect("refresh");  
	});

 
	  
	  function selectEvent(){
		  
		    combox("provinceids","Province",null,null,true);
	  		
		    $("#provinceids").multiselect({
	  			noneSelectedText: "===请选择===",
	  			checkAllText:"全选",
	  			uncheckAllText:"全不选" ,
	  			uncheckAll: function(event, ui){
	  				setCitymultiselect();
	  	        },
	  			selectedText:function(numChecked, numAll, chkItems) {
	  				setCitymultiselect();
	  				return "选中【"+numChecked+"】项 ,共【 "+numAll+"】项";
	  	        }
	  	        
	  		});
		    setCitymultiselect();
	  }
	  
	  
	  function setCitymultiselect(){
			    var provincesids= $("#provinceids").multiselect().multiselect("getChecked").map(function() {
	                return this.value;
	            }).get();
				
				 $("#cityids").multiselect().multiselect("destroy").hide();
				 combox("cityids","City",provincesids,null,true);
		  		 $("#cityids").multiselect({
		  			noneSelectedText: "===请选择===",
		  			checkAllText:"全选",
		  			uncheckAllText:"全不选",
		  		    selectedText: "选中【#】项 ,共【 #】项"
		  		 });
	  }
	  
	  var dataform;
	  function submitFormdata(){
		  
		     var task=getUrlParamVal('task');
		     
		     dataform.form();
    	     if(dataform.valid()){
                var a,url;
                var nowtime = new Date();
                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
                a=strtemp;

                if(task=='add'){
                	url= "${base}/add_conventional_fare/" + a;
                }else if(task=='edit'){
                	url= "${base}/edit_conventional_fare";
                }
                
                $("#loading").showLoading(); 
        		$.ajax({  
	      		      type : "POST",  
	      		      url : url,
	      		      dataType : "json",  
	      		      data:  $("#dataform").serialize(),
	      		      success : function(data) {  
	      		       	    $('#loading').hideLoading();
		      		        if(data.result == true) {
	   
		      			         jAlert("操作成功！","提示", function() {
		      			            parent.window.opener.location.reload();
		                            closeDialog();
		      		             });
	                           
	                        }else if(data.result == false){
	                        	 jAlert("未知错误！");
	                        }
	                        	
	      		      }  
      		    }); 	    	
    	    }
		  
	  }
	  
</script>
</body>